package com.qzsf.backend.mapper.sql;

import org.apache.ibatis.jdbc.SQL;

/*
 * @Author: Dennis Chen
 * @CreateTime: 2024/11/21 21:31 周四
 * @Email 1429278462@qq.com
 * @Remark 多条件筛选报名信息
 * @Version 1.0
 */
public class RegistrationSqlProvider {
    public String getRegistrationByCondition(Integer status, String userName, String eventName) {
        return new SQL() {{
            SELECT("a.id, a.user_id, c.name as userName, a.event_id, b.name as eventName, a.status, a.created_at");
            FROM("registration a");
            LEFT_OUTER_JOIN("event b ON a.event_id = b.id");
            LEFT_OUTER_JOIN("user_profile c ON a.user_id = c.id");

            if (status != null) {
                WHERE("a.status = #{status}");
            }

            if (userName != null) {
                WHERE("c.name LIKE CONCAT('%', #{userName}, '%')");
            }

            if (eventName != null) {
                WHERE("b.name LIKE CONCAT('%', #{eventName}, '%')");
            }
        }}.toString();
    }

}
